#include<iostream>
#include <string>
#include <queue>
using namespace std;
typedef struct node{
    char data;
    struct node *lchild;
    struct node *rchild;
}BTNode;
typedef struct node *BTree;
int GetHeight( BTree BT );
BTree CreateBTree(char *pre,char*in,int n);
int main(){
	int i,n,h;
	char pre[1000],in[1000];	
	BTree BT;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>pre[i];
	for(i=0;i<n;i++)
	cin>>in[i];
	BT=	CreateBTree(pre,in,n);
	h=GetHeight(BT );
	cout<<h;
	return 0;
}
BTree CreateBTree(char *pre,char*in,int n)
{
	BTree s;
	char *p;
	int k;
	if(n<=0)return NULL;
	s=new BTNode;
	s->data=*pre;
	for(p=in;p<in+n;p++)
	if(*p==*pre)
	break;
	k=p-in;
	s->lchild=CreateBTree(pre+1,in,k);
	s->rchild=CreateBTree(pre+k+1,p+1,n-k-1);
	return s;
}
int GetHeight( BTree BT )
{
	int lch,rch;
	if(BT==NULL)return 0;
	else
	{
		lch=GetHeight(BT->lchild);
		rch=GetHeight(BT->rchild);
		return (lch>rch)?(lch+1):(rch+1);
	}
 } 
